package action.creditmanage;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import model.TContract;

import core.action.BaseAction;
import exception.Exceptions;

import service.creditmanage.CreditManageService;
import util.Log;

public class CreditPrintAction extends BaseAction{
	private CreditManageService creditManageService;

	private TContract tc;
	
	private int id;
	private String type;
	private List list;
	private Map<String,Object> printData=new HashMap<String, Object>();
	
	//
	private BigDecimal money;
	private BigDecimal moneyfuli;
	private Timestamp thisdate;
	private Timestamp thatdate;

	private String backmethod;

	public String execute(){
		return "success";
	}
	
	public String printOut() throws Exceptions{
		/*if("change".equals(type)){
			list=creditManageService.getCustomBankList(id,"out");
			if(list==null){
				throw new Exceptions("没有找到客户银行账号!");
			}
		}else{
			
		}*/
		if("do".equals(type)||"sure".equals(type)||"cancel".equals(type)){
			printData=creditManageService.getContract(id,"out");
		}else if("change".equals(type)){
			printData=creditManageService.getContract(id,"outcreate");
		}		
		super.successResultValue="/WEB-INF/content/creditout/loannote.jsp";
		return "function";
	}
	
	public String printOutChange() throws Exceptions{
		if(money==null){
			MessageJump("请填写金额","BACK");
		}else{
			String msg=creditManageService.setOutChange(id,money,thisdate,thatdate);
			if("done".equals(msg)){
				MessageJump("修改完成","../creditout/creditOut!doing");
			}else{
				MessageJump(msg,"../creditout/creditOut!doing");
			}	
			
		}
		return "message";
	}
	
	public String printIn() throws Exceptions{
		if("change".equals(type)||"changeahead".equals(type)){
			printData=creditManageService.getContract(id,"increate");
		}else if("do".equals(type)||"sure".equals(type)||"cancel".equals(type)){
			printData=creditManageService.getContract(id,"in");
		}		
		super.successResultValue="/WEB-INF/content/creditmanage/innote.jsp";
		return "function";
	}
	
	public String printInChange() throws Exceptions{
		if(money==null){
			MessageJump("请填写金额","BACK");
		}else{
			String msg=creditManageService.setInChange(id,money,thisdate,backmethod);
			if("done".equals(msg)){
				MessageJump("还款凭证金额时间修改完成","../creditmanage/creditIn!doing");
			}else{
				MessageJump(msg,"../creditmanage/creditIn!doing");
			}			
		}		
		return "message";
	}
	
	public String printInterest() throws Exceptions{
/*		if("change".equals(type)){
			list=creditManageService.getCustomBankList(id,"interest");
			if(list==null){
				throw new Exceptions("没有找到客户银行账号!");
			}
		}else{
			
		}*/
		if("change".equals(type)){
			printData=creditManageService.getContract(id,"interestcreate");
		}else if("do".equals(type)||"sure".equals(type)||"cancel".equals(type)){
			printData=creditManageService.getContract(id,"interest");
		}	
		
		super.successResultValue="/WEB-INF/content/creditmanage/interestnote.jsp";
		return "function";
	}
	
	public String printInterestChange() throws Exceptions{
		Log.save("aa", "aa", "aa");
		System.out.println(money);
		if(money==null||moneyfuli==null){
			MessageJump("请填写完整","BACK");
		}else{
			String msg=creditManageService.setInterestChange(id,money,thisdate,moneyfuli);
			if("done".equals(msg)){
				MessageJump("金额时间修改完成","../creditmanage/creditInterest!doing");
			}else{
				MessageJump(msg,"../creditmanage/creditInterest!doing");
			}			
		}
		return "message";
	}
	
	public CreditManageService getCreditManageService() {
		return creditManageService;
	}

	public void setCreditManageService(CreditManageService creditManageService) {
		this.creditManageService = creditManageService;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Map<String,Object> getPrintData() {
		return printData;
	}

	public void setPrintData(Map<String,Object> printData) {
		this.printData = printData;
	}

	public TContract getTc() {
		return tc;
	}

	public void setTc(TContract tc) {
		this.tc = tc;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public BigDecimal getMoney() {
		return money;
	}

	public void setMoney(BigDecimal money) {
		this.money = money;
	}

	public Timestamp getThisdate() {
		return thisdate;
	}

	public void setThisdate(Timestamp thisdate) {
		this.thisdate = thisdate;
	}

	public Timestamp getThatdate() {
		return thatdate;
	}

	public void setThatdate(Timestamp thatdate) {
		this.thatdate = thatdate;
	}

	public String getBackmethod() {
		return backmethod;
	}

	public void setBackmethod(String backmethod) {
		this.backmethod = backmethod;
	}

	public BigDecimal getMoneyfuli() {
		return moneyfuli;
	}

	public void setMoneyfuli(BigDecimal moneyfuli) {
		this.moneyfuli = moneyfuli;
	}

}
